package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysStar;
import com.ruoyi.system.service.ISysStarService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿者之星Controller
 * 
 * @author zk
 * @date 2021-11-08
 */
@Controller
@RequestMapping("/system/star")
public class SysStarController extends BaseController
{
    private String prefix = "system/star";

    @Autowired
    private ISysStarService sysStarService;

    @RequiresPermissions("system:star:view")
    @GetMapping()
    public String star()
    {
        return prefix + "/star";
    }

    /**
     * 查询志愿者之星列表
     */
    @RequiresPermissions("system:star:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysStar sysStar)
    {
        startPage();
        List<SysStar> list = sysStarService.selectSysStarList(sysStar);
        return getDataTable(list);
    }

    /**
     * 导出志愿者之星列表
     */
    @RequiresPermissions("system:star:export")
    @Log(title = "志愿者之星", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysStar sysStar)
    {
        List<SysStar> list = sysStarService.selectSysStarList(sysStar);
        ExcelUtil<SysStar> util = new ExcelUtil<SysStar>(SysStar.class);
        return util.exportExcel(list, "志愿者之星数据");
    }

    /**
     * 新增志愿者之星
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存志愿者之星
     */
    @RequiresPermissions("system:star:add")
    @Log(title = "志愿者之星", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysStar sysStar)
    {
        return toAjax(sysStarService.insertSysStar(sysStar));
    }

    /**
     * 修改志愿者之星
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysStar sysStar = sysStarService.selectSysStarById(id);
        mmap.put("sysStar", sysStar);
        return prefix + "/edit";
    }

    /**
     * 修改保存志愿者之星
     */
    @RequiresPermissions("system:star:edit")
    @Log(title = "志愿者之星", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysStar sysStar)
    {
        return toAjax(sysStarService.updateSysStar(sysStar));
    }

    /**
     * 删除志愿者之星
     */
    @RequiresPermissions("system:star:remove")
    @Log(title = "志愿者之星", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysStarService.deleteSysStarByIds(ids));
    }
}
